/*
The Official Type of CSGDX-SEC-201701 is SSX1805.
The spi interface is declared in this header file.
*/
#ifndef __SSX1805_H__
#define __SSX1805_H__

#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include "esn.h"

/* ---- DownLink Packet Constant --------------------------------------------------------- */
#define DL_PREAMBLE         0x43534744
#define CLA_WITH_CRC        0x81          //without CRC32
#define CLA_WITHOUR_CRC     0x80          //CLA Parameters without CRC32
#define DL_RESERVED         0x55555555
#define DL_TAIL             0x31373031

/* ---- UpLink Packet Constant ----------------------------------------------------------- */
#define UL_PREAMBLE         0x44544845
#define UL_RESERVED1        0x5A5A5A5A
#define UL_RESERVED2        0x5A5A
#define UL_TAIL             0x32383132

/* ---- Status Response ----------------------------------------------------------------- */
#define BUSY                0x5A
#define READY1              0x42
#define READY2              0x52

/* ---- Length For Downlink & Uplink Packet Size ---------------------------------------- */
//4116=4096+20, including 4096 Payload Bytes & 20 Extra Bytes for Header + Tail.
#define PACKET_LENGTH       4116

//Define a temp Packet Length for Request Packet
#define REQPKT_LENGTH       100

#define GET_RANDOM_NUM_LEN  20
#define GET_SERIAL_NUM_LEN  16

typedef struct _dl_pkt_header
{
    uint32_t    preamble;
    uint32_t    data_len;
    uint8_t     cla;
    uint8_t     ins;
    uint8_t     p1;
    uint8_t     p2;
    uint32_t    res;
}dl_pkt_header;

typedef struct _dl_pkt_tail
{
    uint32_t tail;
}dl_pkt_tail;

typedef struct _ul_pkt_header
{
    uint32_t preamble;
    uint32_t data_len;
    uint16_t stat;
    uint32_t res1;
    uint16_t res2;
}ul_pkt_header;

typedef struct _ul_pkt_tail
{
    uint32_t tail;
}ul_pkt_tail;


extern encrypt_type ssx1805_prob(void);
extern int get_ssx1805_serial_number(char* u8_serial_str);

#endif  /* __SSX1805_H__ */
